package com.hand.hap.demo.filter;

import com.hand.hap.core.IRequest;
import com.hand.hap.security.permission.dto.DataPermissionTableRule;
import com.hand.hap.security.permission.service.impl.DataPermissionCacheContainer;
import com.hand.hap.security.permission.service.impl.DataPermissionRangeFilter;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;

/**
 * @author shuai.wang02@hand-china.com
 * @version 1.0
 * @description
 * @date 2018/8/8 08:32
 */
public class UserMaskRangeFilter extends DataPermissionRangeFilter {

    @Autowired
    DataPermissionCacheContainer container;

    //对应SYS.AUTHORITY_ROLE代码维护中value
    private final String maskRange = "user_lov";

    @Override
    public void doFilter(IRequest iRequest, String tableName, Map data) throws ExecutionException {

        if (iRequest.getUserId().toString().equals("-1")){
            return;
        }
        List<DataPermissionTableRule> ruleCodeList = container.getTableRule(tableName);

        if (ruleCodeList.size()==0){
            return;
        }
        //根据userid获取屏蔽规则
        setRuleDetail(ruleCodeList,maskRange,iRequest.getUserId().toString(),container,data);
    }
}
